package com.example.qing.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.qing.config.AuthAccess;
import com.example.qing.config.LogType;
import com.example.qing.config.MyLogs;
import com.example.qing.pojo.Novel;
import com.example.qing.pojo.Photo;
import com.example.qing.pojo.Result;
import com.example.qing.service.NovelService;
import com.example.qing.service.PhotoService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/photo")
public class PhotoController {

    @Resource
    PhotoService photoService;

    @AuthAccess
    @GetMapping()
    public Result listAll() {
        List<Photo>photoList = photoService.list();
        return Result.success(photoList);
    }

    @GetMapping("/list")
    public Result list(@RequestParam String albumName) {
        QueryWrapper<Photo>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("album_name",albumName);
        List<Photo>photoList = photoService.list(queryWrapper);
        return Result.success(photoList);
    }


    @MyLogs(operation = "相片",type = LogType.DELETE)
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id){
        photoService.removeById(id);
        return Result.success();
    }

    @GetMapping("/total")
    public Result total(@RequestParam String albumName) {
        QueryWrapper<Photo>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("album_name",albumName);
        long total=photoService.count(queryWrapper);
        return Result.success(total);
    }


    @MyLogs(operation = "相片",type = LogType.BATCH_DELETE)
    @DeleteMapping("/delete")
    public Result delete(@RequestBody List<Integer> ids){
        log.info("批量删除");
        photoService.removeByIds(ids);
        return Result.success();
    }

    @MyLogs(operation = "相片",type = LogType.ADD)
    @PostMapping("/add")
    public Result save(@RequestBody Photo photo){
        photoService.save(photo);
        return Result.success();
    }







}
